import randomNumber from "../../commit/differentID";
export default {
  state: {
    List: [],
    watchList: [],
    listId: randomNumber(),
    withdrawList: [],
  },
  mutations: {
    listAll(state, tableList) {
      state.List = tableList;
      state.allList.push(state.List);
      let selectState = JSON.stringify(state.List);
      localStorage.setItem("tableData", selectState);
      state.listId = randomNumber();
      // console.log(state.listId);
      //   console.log(state.List);
    },
    //添加数组
    addList(state, ruleForm) {
      // state.listId++;
      // state.listId = randomNumber();
      // console.log(state.listId);
      state.List.push(ruleForm);
      // console.log(state.List);
      let selectState = JSON.stringify(state.List);
      localStorage.setItem("tableData", selectState);
      state.withdrawList.push(state.List);
    },
    //编辑数组
    editList(state, arr) {
      // console.log(arr);
      state.List.splice(arr[0], 1, arr[1]);
      let selectState = JSON.stringify(state.List);
      localStorage.setItem("tableData", selectState);
      state.withdrawList.push(state.List);
      // console.log(state);
    },
    //删除对应下标数组
    deleteIndexList(state, index) {
      // console.log(state, index);
      state.List.splice(index, 1);
      // console.log(state, index);
      let selectState = JSON.stringify(state.List);
      localStorage.setItem("tableData", selectState);
      state.withdrawList.push(state.List);
    },
    //删除选中
    deleteSelectedMultiple(state, arr) {
      for (let i = 0; i < arr.length; i++) {
        state.List = state.List.filter((value) => {
          return value.id != arr[i].id;
        });
      }
      let selectState = JSON.stringify(state.List);
      localStorage.setItem("tableData", selectState);
      state.withdrawList.push(state.List);
    },

    changewithdraw(state) {
      console.log(state.withdrawList.length);
      if (state.withdrawList.length <= 1) {
        console.log(state.withdrawList);
      } else {
        // state.List = state.withdrawList[state.withdrawList.length - 1];
        console.log(state.List);
        // state.withdrawList.splice(state.withdrawList.length - 1, 1);
        // let selectState = JSON.stringify(state.List);
        // localStorage.setItem("tableData", selectState);
      }
    },
    listWatchlist(state, tableList) {
      //   console.log(state.watchList);
      state.watchList = tableList;
      //   console.log(state.watchList);
    },
    //查找数组
    searchWatchlist(state, content) {
      state.watchList = [];
      for (let i = 0; i < state.List.length; i++) {
        // console.log(state.List[i].name.indexOf(content));
        // console.log(state.List[i]);
        if (state.List[i].name.indexOf(content) !== -1) {
          state.watchList.push(state.List[i]);
        }
      }
      console.log(state.watchList);
    },
  },
  actions: {},
};
